const Koa = require('koa')
const path = require('path')
const koaBody = require('koa-body');
const koaStatic = require('koa-static')
const parameter = require('koa-parameter')
const errHandler = require('./errHandler')
// 导入users路由处理
const router = require('../router')

const app = new Koa()
//路由之前 使用中间件
app.use(koaBody({
    multipart: true,
    formidable: {
        uploadDir: path.join(__dirname, '../uploads'),
        keepExtensions: true,
    }
}));
app.use(koaStatic(path.join(__dirname, '../uploads')))
// 参数校验
app.use(parameter(app))
app.use(router.routes()).use(router.allowedMethods())
//错误处理
app.on('error', errHandler)



module.exports = app